package com.boarsoft.log.mongodb;

import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;

import com.boarsoft.log.store.LogStore;
import com.boarsoft.mongodb.core.MongoDao;
import com.mongodb.client.MongoIterable;

public class LogStoreMongoDBImpl implements LogStore {
	@Autowired
	protected MongoDao dao;

	@Override
	public void append(String app, String addr, String txt) {
		Document d = new Document();
		d.put("v", txt);
		dao.insert(app, addr, d);
	}

	@Override
	public void clean() {
		MongoIterable<String> dbLt = dao.listDatabaseNames();
		for (String dbName: dbLt) {
			dao.getDatabase(dbName);
			//dao.delete(coll, id)
		}
	}
}
